from django.db import models

from django.contrib.auth.models import AbstractUser

class MyUser(AbstractUser):
  phone = models.CharField(max_length=16,null=True,verbose_name="手机号")
  pic = models.CharField(max_length=128,null=True,verbose_name="头像")
  address = models.CharField(max_length=32,null=True,verbose_name="地址")

  def __str__(self):
    return self.username

class AppUid(models.Model):
  uid = models.CharField(max_length=64)
  from_app = models.CharField(max_length=32)
  users = models.ForeignKey(MyUser,on_delete=models.CASCADE,null=True)


class Goods(models.Model):
  name = models.CharField(max_length=128,verbose_name="商品名称")
  price = models.IntegerField(null=True,verbose_name="价格")
  number = models.IntegerField(default=2000,verbose_name="库存")
  color = models.CharField(max_length=32,verbose_name="颜色")
  size = models.CharField(max_length=128,verbose_name="尺寸")
  version = models.CharField(max_length=32,verbose_name="版本")
  content = models.CharField(max_length=512,verbose_name="简介")
  detall = models.TextField(verbose_name="商品详情")
  picture = models.CharField(max_length=128,default=None,verbose_name="商品图片")

class Lian(models.Model):
  name1 = models.CharField(max_length=32,null=True)
  name = models.TextField()


class LianXi(models.Model):
  name = models.CharField(max_length=32,verbose_name="类型")
  p_id= models.ForeignKey("self",on_delete=models.CASCADE,null=True)

class Cart(models.Model):
  id = models.AutoField(primary_key=True)
  name = models.CharField(max_length=200)
  image_url = models.CharField(max_length=255)
  price = models.FloatField(null=True)
  number = models.IntegerField(default=0)
  goods_id = models.ForeignKey(Goods,on_delete=models.CASCADE,null=True)
  user_id = models.ForeignKey(MyUser,on_delete=models.CASCADE,null=True)


class Orders(models.Model):
  order_sn = models.CharField(max_length=100,unique=True)
  price = models.FloatField(null=True)
  user_id = models.ForeignKey(MyUser,on_delete=models.CASCADE,null=True)
  pay_type = models.IntegerField(default=2) #支付方式  1微信  ，2支付宝  3网银
  status = models.IntegerField(default=0)  #订单状态  0 支付  1支付成功  2失败  3评论
  address = models.CharField(max_length=255)  #地址
  code = models.CharField(max_length=100,default="")  #流水号（支付成功后返回）
















